<?php
/**
 * Base sfGuardAuth actions, overriden here just to have the myActions features
 *
 * @package    symfony
 * @subpackage plugin
 */
class BasesfGuardAuthActions extends myActions
{
  public function executeSignin(sfWebRequest $request)
  {
    $user = $this->getUser();
    if ($user->isAuthenticated())
    {
      return $this->redirect('@homepage');
    }

    $this->form = new SigninForm();

    if ($request->isMethod('post'))
    {
      $this->form->bind($request->getParameter('signin'));

      if ($this->form->isValid())
      {
        $values = $this->form->getValues();
        $this->getUser()->signin($values['user'], 'on' === $values['remember']);

        $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $request->getReferer());
        return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage');
      }
    }
    else
    {
      if ($request->isXmlHttpRequest())
      {
        $this->getResponse()->setHeaderOnly(true);
        $this->getResponse()->setStatusCode(401);

        return sfView::NONE;
      }

      $user->setReferer($request->getReferer());

      $module = sfConfig::get('sf_login_module');
      if ($this->getModuleName() != $module)
      {
        return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
      }

      $this->getResponse()->setStatusCode(401);
    }
  }

  public function executeSignout(sfWebRequest $request)
  {
    $this->getUser()->signOut();
      $this->form = new SigninForm();
    $signout_url = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());

    //$this->redirect('' != $signout_url ? $signout_url : '@homepage');
    $this->redirect('@homepage');
  }

  public function executeSecure()
  {
  	 $this->form = new SigninForm();
    $this->getResponse()->setStatusCode(403);
  }

  public function executePassword()
  {
    throw new sfException('This method is not yet implemented.');
  }
}
